<!DOCTYPE html>





<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="generator" content="Hexo 3.9.0">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.3.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.3.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.3.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '7.3.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    save_scroll: false,
    copycode: {"enable":false,"show_result":false,"style":null},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="C++ 基础知识备忘常用字符串函数头文件include&amp;lt;string.h&amp;gt;1234strlen() // 实际字符串长度，不包括&apos;\0&apos;strcpy(dest,src) // 复制字符串，包括&apos;\0&apos;,如果src大于dest，crashstrncpy(dest,src,num) // 复制n个字符，不包括&apos;\0&apos;,如果src大于num，只复制num个const char *strstr">
<meta name="keywords" content="C++11">
<meta property="og:type" content="article">
<meta property="og:title" content="C++编程指南">
<meta property="og:url" content="http://yoursite.com/2019/05/30/C++编程指南/index.html">
<meta property="og:site_name" content="XuQi&#39;s Blog">
<meta property="og:description" content="C++ 基础知识备忘常用字符串函数头文件include&amp;lt;string.h&amp;gt;1234strlen() // 实际字符串长度，不包括&apos;\0&apos;strcpy(dest,src) // 复制字符串，包括&apos;\0&apos;,如果src大于dest，crashstrncpy(dest,src,num) // 复制n个字符，不包括&apos;\0&apos;,如果src大于num，只复制num个const char *strstr">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-10-20T13:23:23.037Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="C++编程指南">
<meta name="twitter:description" content="C++ 基础知识备忘常用字符串函数头文件include&amp;lt;string.h&amp;gt;1234strlen() // 实际字符串长度，不包括&apos;\0&apos;strcpy(dest,src) // 复制字符串，包括&apos;\0&apos;,如果src大于dest，crashstrncpy(dest,src,num) // 复制n个字符，不包括&apos;\0&apos;,如果src大于num，只复制num个const char *strstr">
  <link rel="canonical" href="http://yoursite.com/2019/05/30/C++编程指南/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>C++编程指南 | XuQi's Blog</title>
  








  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  <div class="container sidebar-position-left">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">XuQi's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
  </ul>

    

</nav>
</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content page-post-detail">
            

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/05/30/C++编程指南/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="XuQi">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="XuQi's Blog">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">C++编程指南

            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-05-30 21:41:32" itemprop="dateCreated datePublished" datetime="2019-05-30T21:41:32+00:00">2019-05-30</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-10-20 13:23:23" itemprop="dateModified" datetime="2019-10-20T13:23:23+00:00">2019-10-20</time>
              </span>
            
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="C-基础知识备忘"><a href="#C-基础知识备忘" class="headerlink" title="C++ 基础知识备忘"></a>C++ 基础知识备忘</h1><h3 id="常用字符串函数"><a href="#常用字符串函数" class="headerlink" title="常用字符串函数"></a>常用字符串函数</h3><h5 id="头文件"><a href="#头文件" class="headerlink" title="头文件"></a>头文件</h5><h5 id="include-lt-string-h-gt"><a href="#include-lt-string-h-gt" class="headerlink" title="include&lt;string.h&gt;"></a>include&lt;string.h&gt;</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">strlen</span>() <span class="comment">// 实际字符串长度，不包括'\0'</span></span><br><span class="line"><span class="built_in">strcpy</span>(dest,src) <span class="comment">// 复制字符串，包括'\0',如果src大于dest，crash</span></span><br><span class="line"><span class="built_in">strncpy</span>(dest,src,num) <span class="comment">// 复制n个字符，不包括'\0',如果src大于num，只复制num个</span></span><br><span class="line"><span class="function"><span class="keyword">const</span> <span class="keyword">char</span> *<span class="title">strstr</span><span class="params">(<span class="keyword">const</span> <span class="keyword">char</span> *str1, <span class="keyword">const</span> <span class="keyword">char</span> *str2)</span></span>; <span class="comment">// 在str1中查找str2,返回找到的起始地址，如果没找到返回null</span></span><br></pre></td></tr></table></figure>

<a id="more"></a>



<h3 id="函数重载定义"><a href="#函数重载定义" class="headerlink" title="函数重载定义"></a>函数重载定义</h3><p>C++特性，因为C++编译后的名字是带参数类型，所以相同函数名，参数不同(类型，个数，顺序)</p>
<p><strong>当心隐式类型转换导致重载函数产生二义性</strong></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">output</span><span class="params">(<span class="keyword">int</span> i)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="string">"int:"</span> &lt;&lt; i &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">output</span><span class="params">(<span class="keyword">float</span> i)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="built_in">cout</span> &lt;&lt; <span class="string">"float"</span> &lt;&lt; i &lt;&lt; <span class="built_in">endl</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">output(<span class="number">0.5</span>); <span class="comment">//无法编译通过</span></span><br></pre></td></tr></table></figure>

<p><strong>全局函数和成员函数重名时，并非重载，如果调用全局函数需要::funtion</strong></p>
<h4 id="成员函数的重载，覆盖和隐藏"><a href="#成员函数的重载，覆盖和隐藏" class="headerlink" title="成员函数的重载，覆盖和隐藏"></a>成员函数的重载，覆盖和隐藏</h4><h5 id="重载和覆盖"><a href="#重载和覆盖" class="headerlink" title="重载和覆盖"></a>重载和覆盖</h5><h6 id="成员函数重载特征"><a href="#成员函数重载特征" class="headerlink" title="成员函数重载特征"></a>成员函数重载特征</h6><ul>
<li>相同范围内（同一个类中）</li>
<li>函数名相同</li>
<li>参数不同</li>
<li>virtual 可有可无</li>
<li>返回值可以不同</li>
</ul>
<h6 id="覆盖-override派生类覆盖基类-的特征"><a href="#覆盖-override派生类覆盖基类-的特征" class="headerlink" title="覆盖(override派生类覆盖基类)的特征"></a>覆盖(override派生类覆盖基类)的特征</h6><ul>
<li>不同范围</li>
<li>函数名字相同</li>
<li>参数相同</li>
<li>基类必须有virtual</li>
</ul>
<h6 id="令人迷惑的隐藏"><a href="#令人迷惑的隐藏" class="headerlink" title="令人迷惑的隐藏"></a>令人迷惑的隐藏</h6><ul>
<li><p><strong>如果派生类函数名和基类相同，但参数不同，无论是否有virtual 基类都被隐藏。</strong></p>
</li>
<li><p><strong>如果派生类函数名和基类相同，参数也相同，基类没有virtual,基类被隐藏。</strong></p>
</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Base</span> </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">	<span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">a</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base a"</span>;&#125;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">b</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base b"</span>;&#125;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">c</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base c"</span>;&#125;</span><br><span class="line">  <span class="function"><span class="keyword">void</span> <span class="title">d</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base d"</span>;&#125;</span><br><span class="line">  <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">f</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base f1"</span>;&#125;</span><br><span class="line">  <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">f</span><span class="params">(<span class="keyword">int</span> i,<span class="keyword">int</span> j)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Base f2"</span>;&#125; </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Device</span>:</span><span class="keyword">public</span> Base</span><br><span class="line">&#123;</span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">	<span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">a</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Device a"</span>;&#125;</span><br><span class="line">	<span class="function"><span class="keyword">void</span> <span class="title">b</span><span class="params">(<span class="keyword">float</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Device b"</span>;&#125;</span><br><span class="line">	<span class="function"><span class="keyword">void</span> <span class="title">c</span><span class="params">(<span class="keyword">int</span> i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Device c"</span>;&#125;</span><br><span class="line">	<span class="function"><span class="keyword">void</span> <span class="title">d</span><span class="params">(<span class="keyword">char</span> *i)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Device d"</span>;&#125;</span><br><span class="line">	<span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">f</span><span class="params">(<span class="keyword">int</span> i,<span class="keyword">int</span> j = <span class="number">0</span>)</span> </span>&#123;<span class="built_in">cout</span> &lt;&lt; <span class="string">"Device f"</span>;&#125; <span class="comment">// 没有覆盖Base的f2，缺省不一样</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  Device d;</span><br><span class="line">  Base *bp = &amp;d;</span><br><span class="line">  Device *dp = &amp;d;</span><br><span class="line">  </span><br><span class="line">  <span class="comment">// good</span></span><br><span class="line">  bp-&gt;a(<span class="number">1</span>); <span class="comment">// call Device a</span></span><br><span class="line">  dp-&gt;a(<span class="number">1</span>); <span class="comment">// call Device a</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">// bad,depend on point type</span></span><br><span class="line">  bp-&gt;b(<span class="number">1.0</span>); <span class="comment">// call Base b</span></span><br><span class="line">  dp-&gt;b(<span class="number">1</span>); <span class="comment">// call Device b</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">// bad,depend on point type</span></span><br><span class="line">  bp-&gt;c(<span class="number">1</span>); <span class="comment">// call Base b</span></span><br><span class="line">  dp-&gt;c(<span class="number">1</span>); <span class="comment">// call Device b</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">// bad,depend on point type</span></span><br><span class="line">  dp-&gt;d(<span class="number">1</span>); <span class="comment">// error,can not call Base d</span></span><br><span class="line">  </span><br><span class="line">  bp-&gt;f(<span class="number">1</span>); <span class="comment">// call Base f1</span></span><br><span class="line">  dp-&gt;f(<span class="number">1</span>); <span class="comment">// call Device f</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="参数的缺省值"><a href="#参数的缺省值" class="headerlink" title="参数的缺省值"></a>参数的缺省值</h6><ul>
<li><p>参数缺省只能出现在声明</p>
</li>
<li><p>如果有多个参数，参数只能从后往前按个缺省</p>
</li>
</ul>
<h5 id="运算符重载"><a href="#运算符重载" class="headerlink" title="运算符重载"></a>运算符重载</h5><h6 id="两种实现方式"><a href="#两种实现方式" class="headerlink" title="两种实现方式"></a>两种实现方式</h6><ul>
<li>友元函数</li>
<li>类成员函数</li>
</ul>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Base</span> &#123;</span></span><br><span class="line"><span class="keyword">public</span>:</span><br><span class="line">    Base(<span class="keyword">int</span> i):m_value(i)&#123;&#125;;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">int</span> <span class="keyword">operator</span> +(Base b) &#123;     <span class="comment">// ;类成员函数实现+</span></span><br><span class="line">        <span class="keyword">return</span> b.m_value + m_value;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">friend</span> <span class="keyword">int</span> <span class="keyword">operator</span> * (Base a,Base b); <span class="comment">// 友元函数实现 *</span></span><br><span class="line">    <span class="keyword">int</span> m_value;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> <span class="keyword">operator</span> * (Base a,Base b)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> a.m_value * b.m_value;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="coredump问题调查"><a href="#coredump问题调查" class="headerlink" title="coredump问题调查"></a>coredump问题调查</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;signal.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;execinfo.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;unistd.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;cstdlib&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">recvSignal</span><span class="params">(<span class="keyword">int</span> sig)</span> </span>&#123;</span><br><span class="line">    <span class="keyword">void</span> *buffer[<span class="number">1024</span>];</span><br><span class="line">    <span class="keyword">int</span> n  = backtrace(buffer,<span class="number">1024</span>);</span><br><span class="line">    <span class="keyword">char</span> **symbols = backtrace_symbols(buffer,n);</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i ++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt;symbols[i]&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">abort</span>();</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fun1</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> *s  = <span class="number">0</span>;</span><br><span class="line">    (*s) = <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="built_in">std</span>::<span class="built_in">cout</span> &lt;&lt; <span class="string">"Hello, World!"</span> &lt;&lt; <span class="built_in">std</span>::<span class="built_in">endl</span>;</span><br><span class="line">    signal(SIGSEGV,recvSignal);</span><br><span class="line">	fun1();</span><br><span class="line">    <span class="keyword">while</span>(<span class="number">1</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">xuqi@xuqi-VirtualBox:~$ g++ main.cpp </span><br><span class="line">xuqi@xuqi-VirtualBox:~$ ./a.out </span><br><span class="line">Hello, World!</span><br><span class="line">./a.out() [<span class="number">0</span>x400a1a]</span><br><span class="line">/lib/x86_64-linux-gnu/libc.so.<span class="number">6</span>(+<span class="number">0</span>x354b0) [<span class="number">0</span>x7fa41205d4b0]</span><br><span class="line">./a.out() [<span class="number">0</span>x400ac9]</span><br><span class="line">./a.out() [<span class="number">0</span>x400b1a]</span><br><span class="line">/lib/x86_64-linux-gnu/libc.so.<span class="number">6</span>(__libc_start_main+<span class="number">0</span>xf0) [<span class="number">0</span>x7fa412048830]</span><br><span class="line">./a.out() [<span class="number">0</span>x400919]</span><br><span class="line">已放弃 (核心已转储)</span><br><span class="line">xuqi@xuqi-VirtualBox:~$ addr2line -e a.out <span class="number">0</span>x400ac9 -f -i -C</span><br><span class="line">fun1()</span><br><span class="line">??:?</span><br></pre></td></tr></table></figure>

<h3 id="字节序列"><a href="#字节序列" class="headerlink" title="字节序列"></a>字节序列</h3><table>
<thead>
<tr>
<th><strong>端序</strong></th>
<th><strong>内存案例(0x44332211)</strong></th>
<th><strong>处理器家族</strong></th>
</tr>
</thead>
<tbody><tr>
<td>大端(Big Endian)</td>
<td>0x44 0x33 0x22 0x11</td>
<td>SUN SPARC/IBM PowerPC</td>
</tr>
<tr>
<td>小端(Little Endian)</td>
<td>0x11 0x22 0x33 0x44</td>
<td>Intel 80x86 系列</td>
</tr>
</tbody></table>
<p>以unsigned int value = 0x12345678为例，分别看看在两种字节序下其存储情况，我们可以用unsigned char buf[4]来表示value：</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">大端Big-Endian: 低地址存放高位，如下：</span><br><span class="line">高地址</span><br><span class="line">        ---------------</span><br><span class="line">        buf[<span class="number">3</span>] (<span class="number">0x78</span>) -- 			 低位数据</span><br><span class="line">        buf[<span class="number">2</span>] (<span class="number">0x56</span>)</span><br><span class="line">        buf[<span class="number">1</span>] (<span class="number">0x34</span>)</span><br><span class="line">        buf[<span class="number">0</span>] (<span class="number">0x12</span>) -- 低地址 高位数据</span><br><span class="line">        ---------------</span><br><span class="line">低地址</span><br><span class="line"></span><br><span class="line">小端Little-Endian: 低地址存放低位，如下：</span><br><span class="line">高地址</span><br><span class="line">        ---------------</span><br><span class="line">        buf[<span class="number">3</span>] (<span class="number">0x12</span>) -- 			 高位数据</span><br><span class="line">        buf[<span class="number">2</span>] (<span class="number">0x34</span>)</span><br><span class="line">        buf[<span class="number">1</span>] (<span class="number">0x56</span>)</span><br><span class="line">        buf[<span class="number">0</span>] (<span class="number">0x78</span>) -- 低地址 低位数据</span><br><span class="line">        --------------</span><br><span class="line">低地址</span><br></pre></td></tr></table></figure>

<p><strong>大端小端没有谁优谁劣，各自优势便是对方劣势：</strong></p>
<p>小端模式 ：强制转换数据不需要调整字节内容，1、2、4字节的存储方式一样。<br>大端模式 ：符号位的判定固定为第一个字节，容易判断正负。</p>
<p> MSB:MoST Significant Bit ——- 最高有效位</p>
<p> LSB:Least Significant Bit ——- 最低有效位</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">IsBigEndian</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> a = <span class="number">0x1234</span>;</span><br><span class="line">    <span class="keyword">char</span> b =  *(<span class="keyword">char</span> *)&amp;a;  </span><br><span class="line">    <span class="comment">//通过将int强制类型转换成char单字节，通过判断起始存储位置。即等于 取b等于a的低地址部分</span></span><br><span class="line">    <span class="keyword">if</span>( b == <span class="number">0x12</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">"大端"</span> &lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">cout</span> &lt;&lt;<span class="string">"小端"</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Log输出格式化"><a href="#Log输出格式化" class="headerlink" title="Log输出格式化"></a>Log输出格式化</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;unistd.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;time.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;sys/syscall.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MY_DEBUG(fmt, args...) printf(<span class="meta-string">"%s %s[%d] "</span> fmt <span class="meta-string">"\n"</span>, timeString(), __FUNCTION__,__LINE__,##args)</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">char</span> * <span class="title">timeString</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">timespec</span> <span class="title">ts</span>;</span></span><br><span class="line">    clock_gettime( CLOCK_REALTIME, &amp;ts);</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">tm</span> * <span class="title">timeinfo</span> = <span class="title">localtime</span>(&amp;<span class="title">ts</span>.<span class="title">tv_sec</span>);</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">char</span> timeStr[<span class="number">20</span>];</span><br><span class="line">    <span class="built_in">sprintf</span>(timeStr, <span class="string">"%.2d:%.2d:%.2d.%.3ld"</span>, timeinfo-&gt;tm_mon + <span class="number">1</span>, timeinfo-&gt;tm_mday, timeinfo-&gt;tm_hour, timeinfo-&gt;tm_min, timeinfo-&gt;tm_sec, ts.tv_nsec / <span class="number">1000000</span>);</span><br><span class="line">    <span class="keyword">return</span> timeStr;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h5 id="①args…"><a href="#①args…" class="headerlink" title="①args…"></a>①args…</h5><p>​    第一个传给fmt, 第二个开始传给args…可为多个。</p>
<h5 id="②-args"><a href="#②-args" class="headerlink" title="②##args"></a>②##args</h5><pre><code>##args的意思，就是把args...中的多个参数，串连起来。
#fmt的话，就是把fmt传进来的内容以字符串形式输出</code></pre><h3 id="拷贝构造函数和赋值函数"><a href="#拷贝构造函数和赋值函数" class="headerlink" title="拷贝构造函数和赋值函数"></a>拷贝构造函数和赋值函数</h3><h5 id="1-如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。"><a href="#1-如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。" class="headerlink" title="1. 如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。"></a>1. 如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。</h5><p><strong>隐含错误包括</strong></p>
<ul>
<li><p>原有的内存没有被释放，造成内存泄漏。</p>
</li>
<li><p>两个指针指向同一块内存，任何一方改动都会影响另一方。</p>
</li>
<li><p>对象析构，数据被释放了两次。</p>
</li>
</ul>
<h5 id="2-拷贝构造函数和赋值函数的区别"><a href="#2-拷贝构造函数和赋值函数的区别" class="headerlink" title="2. 拷贝构造函数和赋值函数的区别"></a>2. 拷贝构造函数和赋值函数的区别</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">String <span class="title">a</span><span class="params">(<span class="string">"hello"</span>)</span></span>;</span><br><span class="line"><span class="function">String <span class="title">b</span><span class="params">(<span class="string">"world"</span>)</span></span>;</span><br><span class="line">String c = a; <span class="comment">// 拷贝构造函数，最好写成String c(a);</span></span><br><span class="line">c = b; <span class="comment">// 调用赋值函数</span></span><br></pre></td></tr></table></figure>

<h5 id="3-关键字explicit"><a href="#3-关键字explicit" class="headerlink" title="3. 关键字explicit"></a>3. 关键字explicit</h5><blockquote>
<p>可以禁止“单参数构造函数”被用于自动类型转换，没有explicit的话test s = 4;能编译通过</p>
</blockquote>
<h5 id="4-派生函数应该是virtual-函数，否则派生类析构时，基类无法析构"><a href="#4-派生函数应该是virtual-函数，否则派生类析构时，基类无法析构" class="headerlink" title="4. 派生函数应该是virtual 函数，否则派生类析构时，基类无法析构"></a>4. 派生函数应该是virtual 函数，否则派生类析构时，基类无法析构</h5><h5 id="5-派生函数的赋值函数，需要对基类成员也做赋值"><a href="#5-派生函数的赋值函数，需要对基类成员也做赋值" class="headerlink" title="5. 派生函数的赋值函数，需要对基类成员也做赋值"></a>5. 派生函数的赋值函数，需要对基类成员也做赋值</h5><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Derived &amp; Derived::operate =(<span class="keyword">const</span> Derived &amp;other) </span><br><span class="line">&#123;</span><br><span class="line">  <span class="comment">//(1)检查自赋值 </span></span><br><span class="line">  <span class="keyword">if</span>(<span class="keyword">this</span> == &amp;other)</span><br><span class="line">  <span class="keyword">return</span> *<span class="keyword">this</span>;</span><br><span class="line">  <span class="comment">//(2)对基类的数据成员重新赋值</span></span><br><span class="line">  Base::operate =(other); <span class="comment">// 因为不能直接操作私有数据成员</span></span><br><span class="line">  <span class="comment">//(3)对派生类的数据成员赋值 </span></span><br><span class="line">  m_x = other.m_x;</span><br><span class="line">  m_y = other.m_y;</span><br><span class="line">  m_z = other.m_z;</span><br><span class="line">  <span class="comment">//(4)返回本对象的引用</span></span><br><span class="line">  <span class="keyword">return</span> *<span class="keyword">this</span>; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="模板学习之typename"><a href="#模板学习之typename" class="headerlink" title="模板学习之typename"></a>模板学习之typename</h3><p>模板的声明可以使用关键字class代替typename进行,这两种声明方式没有任何的区别，其意义是完全一样的</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt; <span class="class"><span class="keyword">class</span> <span class="title">Widget</span>;</span> <span class="comment">// uses "typename"</span></span><br></pre></td></tr></table></figure>

<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;<span class="class"><span class="keyword">class</span> <span class="title">T</span>&gt; <span class="title">class</span> <span class="title">Widget</span>;</span> <span class="comment">// uses "typename"</span></span><br></pre></td></tr></table></figure>

<p>但是typename还有另外的使用方法</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> C&gt; <span class="comment">// print 2nd element in</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print2nd</span><span class="params">(<span class="keyword">const</span> C&amp; container)</span> <span class="comment">// container;</span></span></span><br><span class="line"><span class="function"></span>&#123; </span><br><span class="line">　<span class="comment">// this is not valid C++!</span></span><br><span class="line">　<span class="keyword">if</span> (container.size() &gt;= <span class="number">2</span>) &#123;</span><br><span class="line">   <span class="comment">// 代码有问题</span></span><br><span class="line">　　C::<span class="function">const_iterator <span class="title">iter</span><span class="params">(container.begin())</span></span>; <span class="comment">// get iterator to 1st element</span></span><br><span class="line">　　++iter; <span class="comment">// move iter to 2nd element</span></span><br><span class="line">　　<span class="keyword">int</span> value = *iter; <span class="comment">// copy that element to an int</span></span><br><span class="line">　　<span class="built_in">std</span>::<span class="built_in">cout</span> &lt;&lt; value; <span class="comment">// print the int</span></span><br><span class="line">　&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果C::const_iterator是一个类型，则定义了一个C::const_iterator类型的指针x，而如果C::const_iterator是类型C的一个成员变量呢，如果x正好是一个全局变量呢，这个表达式就是两个变量的乘积了。此处产生歧义的原因就在于C::iterator意义不明确，它依赖于模板参数，我们将其称为嵌套依赖名字（nested dependent name），为了消除歧义，C++规定，对于嵌套依赖名字，统统不解释为类型，除非显示声明。这就是为什么说上面那段代码有问题，因为编译器不认为C::const_iterator是一个类型。那么如何显示声明C::iterator为一个类型呢，就是使用typename关键字！</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> C&gt; <span class="comment">// print 2nd element in</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print2nd</span><span class="params">(<span class="keyword">const</span> C&amp; container)</span> <span class="comment">// container;</span></span></span><br><span class="line"><span class="function"></span>&#123; </span><br><span class="line">　<span class="comment">// this is not valid C++!</span></span><br><span class="line">　<span class="keyword">if</span> (container.size() &gt;= <span class="number">2</span>) &#123;</span><br><span class="line">　　<span class="keyword">typename</span> C::<span class="function">const_iterator <span class="title">iter</span><span class="params">(container.begin())</span></span>; <span class="comment">// get iterator to 1st element</span></span><br><span class="line">　　++iter; <span class="comment">// move iter to 2nd element</span></span><br><span class="line">　　<span class="keyword">int</span> value = *iter; <span class="comment">// copy that element to an int</span></span><br><span class="line">　　<span class="built_in">std</span>::<span class="built_in">cout</span> &lt;&lt; value; <span class="comment">// print the int</span></span><br><span class="line">　&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="C-11-模板中的-using"><a href="#C-11-模板中的-using" class="headerlink" title="C++11 模板中的 using"></a>C++11 模板中的 using</h3><p>C++ 11 后的类型别名或者模板别名</p>
<p>类型别名是指：之前定义的类型的引用（类似 typedef）</p>
<p>模板别名是指：模板类的引用</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">例子：</span><br><span class="line">　　（<span class="number">1</span>）<span class="keyword">using</span> line_no = <span class="built_in">std</span>::<span class="built_in">vector</span>&lt;<span class="built_in">string</span>&gt;::size_type;</span><br><span class="line"></span><br><span class="line">　　　　相当于：<span class="keyword">typedef</span> <span class="built_in">vector</span>&lt;<span class="built_in">string</span>&gt;::size_type line_no;</span><br><span class="line"></span><br><span class="line">　　（<span class="number">2</span>） <span class="comment">// typedef void (*func)(int, int);</span></span><br><span class="line">　　　　<span class="keyword">using</span> func = <span class="keyword">void</span> (*) (<span class="keyword">int</span>, <span class="keyword">int</span>);　　<span class="comment">// the name 'func' now denotes a pointer to function</span></span><br><span class="line"></span><br><span class="line">　   （<span class="number">3</span>）<span class="keyword">template</span>&lt;<span class="class"><span class="keyword">class</span> <span class="title">CharT</span>&gt;</span></span><br><span class="line"><span class="class"></span></span><br><span class="line"><span class="class">　　　　<span class="title">using</span> <span class="title">mystring</span> = <span class="title">std</span>:</span>:basic_string&lt;CharT,<span class="built_in">std</span>::char_traits&lt;CharT&gt;&gt;;</span><br><span class="line"></span><br><span class="line">　　　　mystring&lt;<span class="keyword">char</span>&gt; str;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    
        
      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/C-11/" rel="tag"># C++11</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2019/05/22/以太网芯片MAC和PHY的关系/" rel="next" title="以太网芯片MAC和PHY的关系">
                  <i class="fa fa-chevron-left"></i> 以太网芯片MAC和PHY的关系
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2019/06/05/C++新特性/" rel="prev" title="C++常用新特性">
                  C++常用新特性 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">XuQi</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">44</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">30</span>
        <span class="site-state-item-name">标签</span>
        
      </div>
    
  </nav>



        </div>
      </div>
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#C-基础知识备忘"><span class="nav-number">1.</span> <span class="nav-text">C++ 基础知识备忘</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#常用字符串函数"><span class="nav-number">1.0.1.</span> <span class="nav-text">常用字符串函数</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#头文件"><span class="nav-number">1.0.1.0.1.</span> <span class="nav-text">头文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#include-lt-string-h-gt"><span class="nav-number">1.0.1.0.2.</span> <span class="nav-text">include&lt;string.h&gt;</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#函数重载定义"><span class="nav-number">1.0.2.</span> <span class="nav-text">函数重载定义</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#成员函数的重载，覆盖和隐藏"><span class="nav-number">1.0.2.1.</span> <span class="nav-text">成员函数的重载，覆盖和隐藏</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#重载和覆盖"><span class="nav-number">1.0.2.1.1.</span> <span class="nav-text">重载和覆盖</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#成员函数重载特征"><span class="nav-number">1.0.2.1.1.1.</span> <span class="nav-text">成员函数重载特征</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#覆盖-override派生类覆盖基类-的特征"><span class="nav-number">1.0.2.1.1.2.</span> <span class="nav-text">覆盖(override派生类覆盖基类)的特征</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#令人迷惑的隐藏"><span class="nav-number">1.0.2.1.1.3.</span> <span class="nav-text">令人迷惑的隐藏</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#参数的缺省值"><span class="nav-number">1.0.2.1.1.4.</span> <span class="nav-text">参数的缺省值</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#运算符重载"><span class="nav-number">1.0.2.1.2.</span> <span class="nav-text">运算符重载</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#两种实现方式"><span class="nav-number">1.0.2.1.2.1.</span> <span class="nav-text">两种实现方式</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#coredump问题调查"><span class="nav-number">1.0.3.</span> <span class="nav-text">coredump问题调查</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#字节序列"><span class="nav-number">1.0.4.</span> <span class="nav-text">字节序列</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Log输出格式化"><span class="nav-number">1.0.5.</span> <span class="nav-text">Log输出格式化</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#①args…"><span class="nav-number">1.0.5.0.1.</span> <span class="nav-text">①args…</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#②-args"><span class="nav-number">1.0.5.0.2.</span> <span class="nav-text">②##args</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#拷贝构造函数和赋值函数"><span class="nav-number">1.0.6.</span> <span class="nav-text">拷贝构造函数和赋值函数</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。"><span class="nav-number">1.0.6.0.1.</span> <span class="nav-text">1. 如果不写拷贝构造函数，编译器以位拷贝的方式，所以如果类中有指针变量，就会隐含错误。</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-拷贝构造函数和赋值函数的区别"><span class="nav-number">1.0.6.0.2.</span> <span class="nav-text">2. 拷贝构造函数和赋值函数的区别</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-关键字explicit"><span class="nav-number">1.0.6.0.3.</span> <span class="nav-text">3. 关键字explicit</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4-派生函数应该是virtual-函数，否则派生类析构时，基类无法析构"><span class="nav-number">1.0.6.0.4.</span> <span class="nav-text">4. 派生函数应该是virtual 函数，否则派生类析构时，基类无法析构</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#5-派生函数的赋值函数，需要对基类成员也做赋值"><span class="nav-number">1.0.6.0.5.</span> <span class="nav-text">5. 派生函数的赋值函数，需要对基类成员也做赋值</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#模板学习之typename"><span class="nav-number">1.0.7.</span> <span class="nav-text">模板学习之typename</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#C-11-模板中的-using"><span class="nav-number">1.0.8.</span> <span class="nav-text">C++11 模板中的 using</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">XuQi</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.9.0</div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.3.0</div>

        








        
      </div>
    </footer>
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
      </div>

    

  </div>

  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

<script src="/js/utils.js?v=7.3.0"></script>
  <script src="/js/motion.js?v=7.3.0"></script>


  <script src="/js/schemes/muse.js?v=7.3.0"></script>


<script src="/js/next-boot.js?v=7.3.0"></script>




  




























  

  

  


  
  <script src="/js/scrollspy.js?v=7.3.0"></script>
<script src="/js/post-details.js?v=7.3.0"></script>


</body>
</html>
